package zuoye;

import java.awt.List;
import java.util.Arrays;

public class Bubble6 {
	/*7、int[] arr11 = {1, 2, 3, 4,5,6,7,8,9,0,3,2,4,5,6,7,4,32,2,1,1,4,6,3}; 数组去重*/
	public static void main(String[] args) {
		int[] nums = {1,2,3,4,5,6,7,8,9,0,3,2,4,5,6,7,4,32,2,1,1,4,6,3};
		/*for (int i = 0; i < arr.length; i++) {
			for (int j = i; j < arr.length - 1; j++) {
				if (arr[i] == arr[j + 1]) {
					arr[j + 1] = -1;
				}
			}
		}
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] != -1) {
				System.out.print(arr[i]+" ");
			}
		}*/
		int count = 0; //统计重复元素个数
		for (int i = 0; i < nums.length; i++) {
			for(int j=i+1;j <nums.length;j++) {
				if(nums[i] == nums[j]) {
					count++; 
					break;
				}
			}
		}
		System.out.println("count---------------------->" +count);
		int len = nums.length;
		int size = len - count;
		int[] arr = new int[size]; //4
		int pos = 0,val = 0;
		boolean flag = false;
		//比较新数组arr和旧数组nums元素，如果不相等就保存到新数组arr中。
		for (int i = 0; i < nums.length; i++) {
			val = nums[i];
			flag = false;
			/* i=0
			 * nums = {4,1,1,2,3,2}
			 * arr = {4,0,0,0}
			 * -------------------
			 * i=1
			 * nums = {4,1,1,2,3,2}
			 * arr = {4,1,0,0}
			 * --------------------
			 * i=2
			 * nums = {4,1,1,2,3,2}
			 * arr = {4,1,0,0}
			 * */
			for (int j = 0; j < arr.length; j++) {
				if(nums[i] == arr[j]) {
					flag = true;
					break;
				}
			} //end inner for
			//如果不相等，将此元素存入新数组中
			if(!flag) {
				//{4,1,0,0}
				arr[pos++] = val;  
			}
		} //end outer for
		
		System.out.println(Arrays.toString(arr));
	}
}
